﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace BDH.DAL
{
    using BDH.DAL.Entities;
    public class PhuongDAL : BaseDAL, BDH.UTL.IBaseDAL
    {
        public int Count()
        {
            throw new NotImplementedException();
        }

        public DataTable Select()
        {
            string sql = @" SELECT p.id phuong_id,p.ma,tenphuong, quan_id,q.ten FROM Phuong p JOIN Quan q ON p.quan_id = q.id ";
            return ExecuteQuery(sql);
        }

        public DataTable Select(string id)
        {
            throw new NotImplementedException();
        }

        public DataTable Select(int id)
        {
            string sql = @" SELECT id,ma,tenphuong,quan_id FROM Phuong WHERE quan_id = '{0}' ";
            sql = string.Format(sql, id);
            return ExecuteQuery(sql);
        }

        public DataTable Select(string id1, string id2)
        {
            throw new NotImplementedException();
        }

        public DataTable Select(object obj)
        {
            throw new NotImplementedException();
        }

        public object GetByKey(object key)
        {
            throw new NotImplementedException();
        }

        public bool Delete(long id)
        {
            string sql = @" DELETE FROM Phuong WHERE id = {0} ";
            sql = string.Format(sql, id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Insert(object obj)
        {
            var o = (Phuong)obj;
            string sql = @" INSERT INTO Phuong(ma,tenphuong,quan_id) VALUES('{0}', N'{1}', '{2}') ";
            sql = string.Format(sql, o.ma, o.tenphuong, o.quan_id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }

        public bool Update(object obj)
        {
            var o = (Phuong)obj;
            string sql = @" UPDATE Phuong SET ten = N'{0}' WHERE id = {1} ";
            sql = string.Format(sql, o.tenphuong, o.id);
            return ExecuteNonQuery(sql) > 0 ? true : false;
        }
    }
}
